home *** CD-ROM | disk | FTP | other *** search
/ Amiga Collections: Scope / Scope Disk #142 (199x)(Scope PD)(US)[WB].zip / Scope Disk #142 (199x)(Scope PD)(US)[WB].adf / LoadImage / LibMain.c < prev    next >
C/C++ Source or Header  |  1990-07-30  |  7KB  |  331 lines

  1. /* $Revision Header * Header built automatically - do not edit! *************
  2.  *
  3.  *    (C) Copyright 1990 by MXM
  4.  *
  5.  *    Name .....: LibMain.c
  6.  *    Created ..: Saturday 06-Jan-90 23:30
  7.  *    Revision .: 8
  8.  *
  9.  *    Date            Author          Comment
  10.  *    =========       ========        ====================
  11.  *    26-Apr-90       Olsen           Opened dos.library (always forgot it!)
  12.  *    13-Apr-90       Olsen           Added NULL-function
  13.  *    01-Apr-90       Olsen           Moved library calls
  14.  *    27-Mar-90       Olsen           Added alerts/moved flag checks
  15.  *    26-Mar-90       Olsen           Rearranged LibExpunge/LibClose
  16.  *    16-Mar-90       Olsen           Rework for Aztec 5.0 release
  17.  *    07-Jan-90       Olsen           - Empty log message -
  18.  *    07-Jan-90       Olsen           Moved OpenLibrary call
  19.  *    07-Jan-90       Olsen           - Empty log message -
  20.  *    07-Jan-90       Olsen           Created this file!
  21.  *
  22.  * $Revision Header *********************************************************
  23.  *
  24.  *    This file contains the skeleton library functions employed by
  25.  *    rexxhost.library.
  26.  *
  27.  ***************************************************************************/
  28.  
  29.     /* Imported from RexxHostLib.c */
  30.  
  31. extern LONG Revision;
  32.  
  33.     /* ASCII library ID. */
  34.  
  35. char *LibName    = "rexxhost.library";
  36. char *LibId    = "rexxhost.library 34.12 (26 Apr 1990)\r\n";
  37.  
  38.     /* External data, defined in asm startup code. */
  39.  
  40. extern struct Resident     LibRomTag;
  41. extern LONG         LibInit();
  42.  
  43.     /* Main rexx library base. */
  44.  
  45. struct RxsLib *RexxSysBase;
  46.  
  47.     /* External reference to DOSBase pointer. */
  48.  
  49. extern APTR DOSBase;
  50.  
  51.     /* Pointer to library segment list. */
  52.  
  53. BPTR LibSegList = ZERO;
  54.  
  55.     /* Protos for this module. */
  56.  
  57. struct RexxHostBase *    LibMain(struct RexxHostBase *,BPTR);
  58.  
  59. struct RexxHostBase *    LibOpen(VOID);
  60. BPTR            LibClose(VOID);
  61. BPTR            LibExpunge(VOID);
  62. LONG            LibNull(VOID);
  63.  
  64.     /* And now for the pragmas... */
  65.  
  66. #pragma amicall(RexxHostBase, 0x06, LibOpen())
  67. #pragma amicall(RexxHostBase, 0x0c, LibClose())
  68. #pragma amicall(RexxHostBase, 0x12, LibExpunge())
  69. #pragma amicall(RexxHostBase, 0x18, LibNull())
  70.  
  71.     /* The library initialization. */
  72.  
  73. #pragma regcall(LibMain(d0,a0))
  74.  
  75.     /* The structure expected by the library loader (auto-init). */
  76.  
  77. struct InitTable
  78. {
  79.     ULONG     it_DataSize;    /* Data size to allocate. */
  80.     APTR    *it_FuncTable;    /* Pointer to function table. */
  81.     APTR     it_DataInit;    /* Pointer to data initializers (remember InitStruct?). */
  82.     APTR     it_InitFunc;    /* The real library init function. */
  83. };
  84.  
  85.     /* The list of library functions. */
  86.  
  87. APTR LibFuncTab[] =
  88. {
  89.     LibOpen,        /* Standard library routines. */
  90.     LibClose,
  91.     LibExpunge,
  92.     LibNull,
  93.  
  94.     CreateRexxHost,        /* Now for the real stuff. */
  95.     DeleteRexxHost,
  96.     SendRexxCommand,
  97.     FreeRexxCommand,
  98.     ReplyRexxCommand,
  99.     GetRexxCommand,
  100.     GetRexxArg,
  101.     GetRexxResult1,
  102.     GetRexxResult2,
  103.     GetToken,
  104.     GetStringValue,
  105.     BuildValueString,
  106.     RexxStrCmp,
  107.  
  108.     (APTR)-1        /* End marker. */
  109. };
  110.  
  111.     /* The romtag needs this. */
  112.  
  113. struct InitTable LibInitTab =
  114. {
  115.     sizeof(struct RexxHostBase),    /* Lib base. */
  116.     LibFuncTab,            /* Function table. */
  117.     NULL,                /* No data init table (we'll do autoinit). */
  118.     LibInit                /* Lib init routine. */
  119. };
  120.  
  121.     /* LibMain(RexxHostBase,SegList):
  122.      *
  123.      *    Does the main library initialization, expects
  124.      *    all arguments in registers.
  125.      */
  126.  
  127. struct RexxHostBase *
  128. LibMain(struct RexxHostBase *RexxHostBase,BPTR SegList)
  129. {
  130.     struct RexxHostBase *LibBase = NULL;
  131.  
  132.         /* We want to be initialized only once, the empty
  133.          * seglist will (hopefully) guarantee that.
  134.          */
  135.  
  136.     if(!LibSegList)
  137.     {
  138.         if(DOSBase = (APTR)OpenLibrary("dos.library",0))
  139.         {
  140.                 /* Try to open rexxsyslib.library. */
  141.  
  142.             if(RexxSysBase = (struct RxsLib *)OpenLibrary(RXSNAME,0))
  143.             {
  144.                     /* Remember segment list. */
  145.  
  146.                 LibSegList = SegList;
  147.  
  148.                     /* Seems that all initialization went fine. */
  149.  
  150.                 LibBase = RexxHostBase;
  151.  
  152.                     /* Fill in the library node head. */
  153.  
  154.                 RexxHostBase -> LibNode . lib_Node . ln_Type    = NT_LIBRARY;
  155.                 RexxHostBase -> LibNode . lib_Node . ln_Name    = LibName;
  156.  
  157.                     /* Set the remaining flags. */
  158.  
  159.                 RexxHostBase -> LibNode . lib_Flags        = LIBF_SUMUSED | LIBF_CHANGED;
  160.                 RexxHostBase -> LibNode . lib_Version        = LibRomTag . rt_Version;
  161.                 RexxHostBase -> LibNode . lib_Revision        = Revision;
  162.                 RexxHostBase -> LibNode . lib_IdString        = (APTR)LibId;
  163.  
  164.                     /* Fill in the pointer. */
  165.  
  166.                 RexxHostBase -> RexxSysBase = RexxSysBase;
  167.             }
  168.             else
  169.             {
  170.                 /* Help! Can't open the rexx library! */
  171.  
  172.                 Alert(AT_Recovery | AG_OpenLib,"REXX");
  173.             }
  174.         }
  175.         else
  176.         {
  177.             /* Arrgh! Can't open dos.library! */
  178.  
  179.             Alert(AT_Recovery | AG_OpenLib | AO_DOSLib,"REXX");
  180.         }
  181.     }
  182.  
  183.         /* Return the result (surprise!). */
  184.  
  185.     return(LibBase);
  186. }
  187.  
  188.     /* LibOpen():
  189.      *
  190.      *    Library open routine.
  191.      */
  192.  
  193. struct RexxHostBase *
  194. LibOpen()
  195. {
  196.     struct RexxHostBase *RexxHostBase;
  197.  
  198.         /* If rexxsyslib.library didn't open we refuse
  199.          * to go any further.
  200.          */
  201.  
  202.     if(!RexxSysBase)
  203.         return(NULL);
  204.  
  205.         /* Increment open count and prevent delayed
  206.          * expunges.
  207.          */
  208.  
  209.     RexxHostBase -> LibNode . lib_OpenCnt++;
  210.     RexxHostBase -> LibNode . lib_Flags &= ~LIBF_DELEXP;
  211.  
  212.         /* Return base pointer. */
  213.  
  214.     return(RexxHostBase);
  215. }
  216.  
  217.     /* LibClose():
  218.      *
  219.      *    Closes the library.
  220.      */
  221.  
  222. BPTR
  223. LibClose()
  224. {
  225.     struct RexxHostBase    *RexxHostBase;
  226.     BPTR             SegList = ZERO;
  227.  
  228.         /* Is the library user count ok? */
  229.  
  230.     if(RexxHostBase -> LibNode . lib_OpenCnt > 0)
  231.     {
  232.             /* Decrement user count. */
  233.  
  234.         RexxHostBase -> LibNode . lib_OpenCnt--;
  235.  
  236.             /* Try the expunge. */
  237.  
  238.         SegList = LibExpunge();
  239.     }
  240.     else
  241.     {
  242.         /* One close request after the lib has already
  243.          * shut down? We'll call Mr. Guru.
  244.          */
  245.  
  246.         Alert(AT_Recovery | AG_CloseLib,"HOST");
  247.     }
  248.  
  249.         /* Return the segment list, ramlib will know
  250.          * what to do with it.
  251.          */
  252.  
  253.     return(SegList);
  254. }
  255.  
  256.     /* LibExpunge(RexxHostBase):
  257.      *
  258.      *    Expunge library, careful: this can be called by
  259.      *    ramlib without the rest of the library knowing
  260.      *    about it.
  261.      */
  262.  
  263. BPTR
  264. LibExpunge()
  265. {
  266.     struct RexxHostBase    *RexxHostBase;
  267.     BPTR             SegList = ZERO;
  268.  
  269.         /* Is the user count zero, the delayed expunge flag
  270.          * set and do we have a valid segment list?
  271.          */
  272.  
  273.     if(RexxHostBase -> LibNode . lib_OpenCnt == 0 && (RexxHostBase -> LibNode . lib_Flags & LIBF_DELEXP) && LibSegList)
  274.     {
  275.             /* Remember segment list. */
  276.  
  277.         SegList = LibSegList;
  278.  
  279.             /* Set real segment list to zero which will
  280.              * hopefully keep us from getting expunged
  281.              * twice.
  282.              */
  283.  
  284.         LibSegList = ZERO;
  285.  
  286.             /* Remove library from lib list. */
  287.  
  288.         Remove((struct Node *)RexxHostBase);
  289.  
  290.             /* Close the libraries. */
  291.  
  292.         if(RexxSysBase)
  293.             CloseLibrary(RexxSysBase);
  294.  
  295.         if(DOSBase)
  296.             CloseLibrary(DOSBase);
  297.  
  298.             /* Free library/jumptable memory. */
  299.  
  300.         FreeMem((char *)RexxHostBase - RexxHostBase -> LibNode . lib_NegSize,RexxHostBase -> LibNode . lib_NegSize + RexxHostBase -> LibNode . lib_PosSize);
  301.     }
  302.     else
  303.     {
  304.         /* In any other case we'll set the delayed
  305.          * expunge flag (so next expunge call will
  306.          * hopefully wipe us from the lib list).
  307.          */
  308.  
  309.         RexxHostBase -> LibNode . lib_Flags |= LIBF_DELEXP;
  310.     }
  311.  
  312.         /* Return segment list pointer. */
  313.  
  314.     return(SegList);
  315. }
  316.  
  317.     /* LibNull():
  318.      *
  319.      *    Dummy routine, always returns NULL.
  320.      */
  321.  
  322. LONG
  323. LibNull()
  324. {
  325.     struct RexxHostBase *RexxHostBase;
  326.  
  327.         /* Do nothing useful, return NULL. */
  328.  
  329.     return(NULL);
  330. }
  331.